/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pos.domain;

import com.pos.collection.util.CollectionUtils;
import java.io.Serializable;
import java.util.Collections;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author suraj
 */
@Entity
@Table(name = "purchaseDetails")
public class PurchaseDetails extends ItemTransaction implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long billNumber;
    @OneToOne
    private Vendor vendor;
    @OneToMany(cascade = CascadeType.ALL)
    private Set<PurchaseLineItem> lineItems = CollectionUtils.newHashSet();

    public long getBillNumber() {
        return billNumber;
    }

    public void setBillNumber(long billNumber) {
        this.billNumber = billNumber;
    }

    public Vendor getVendor() {
        return vendor;
    }

    public void setVendor(Vendor vendor) {
        this.vendor = vendor;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PurchaseDetails other = (PurchaseDetails) obj;
        if (this.billNumber != other.billNumber) {
            return false;
        }
        if (this.vendor != other.vendor && (this.vendor == null || !this.vendor.equals(other.vendor))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 23 * hash + (int) (this.billNumber ^ (this.billNumber >>> 32));
        hash = 23 * hash + (this.vendor != null ? this.vendor.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return String.valueOf(this.billNumber);
    }

    @Override
    public void addItem(LineItem item) {
        this.lineItems.add((PurchaseLineItem) item);
    }

    public void setLineItems(Set<PurchaseLineItem> lineItems) {
        this.lineItems = lineItems;
    }

    @Override
    public Set getLineItems() {
        return Collections.unmodifiableSet(lineItems);
    }
}
